import store from '@/store/index.js'
//封装Get请求-加盟商专用
function requestGetMethod(url,params){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:url,
			data:params,
			header:{
				"Authorization":uni.getStorageSync('Authorization'),
			},
			method:'GET',
			dataType:'json',
			success: (res) => {
				if(res.statusCode == 401) {
					store.commit('setToken', '');
					store.commit('setUserInfo',{});
					uni.removeStorageSync('Authorization')
					uni.removeStorageSync('userInfo')
					resolve(res.data);
				} else if(res.statusCode == 200) {
					resolve(res.data);
				} else {
					console.log(res)
					resolve(res.data);
				}			
			},
			fail: (res) => {
				console.log(res)
				reject(res.data);
			}
		});
	});
}
//封装post请求--加盟商专用
function requestPostMethod(url,params){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:url,
			data:params,
			header:{
				"Authorization":uni.getStorageSync('Authorization')
			},
			method:'POST',
			dataType:'json',
			success: (res) => {
				if(res.statusCode == 401) {
					store.commit('setToken', '');
					store.commit('setUserInfo',{});
					uni.removeStorageSync('Authorization')
					uni.removeStorageSync('userInfo')
					resolve(res.data);
				} else if(res.statusCode == 200) {
					resolve(res.data);
				} else {
					console.log(res)
					resolve(res.data);
				}	
			},
			fail: (res) => {
				console.log(res)
				reject(res.data);
			}
		});
	});
}
module.exports={
	requestGetMethod,
	requestPostMethod
}